package com.infinite.service;

import com.infinite.mapper.DepartmentMapper;
import com.infinite.mapper.EmployeeMapper;
import com.infinite.pojo.Department;
import com.infinite.pojo.Employee;
import com.infinite.vo.EmployeeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    DepartmentMapper departmentMapper;
    @Override
    public List<EmployeeVo> getAllEmployee() {
        ArrayList<EmployeeVo> employeeVos = new ArrayList<>();
        Collection<Employee> employees = employeeMapper.getAllEmployee();
        for (Employee employee : employees) {
            EmployeeVo employeeVo = new EmployeeVo();
            String departmentName = departmentMapper.getDepartmentById(employee.getDeptId()).getDepartmentName();
            employeeVo.setEmployee(employee);
            employeeVo.setDepartmentName(departmentName);
            employeeVos.add(employeeVo);
        }
        return employeeVos;


    }
}
